What are SQL Views?
131
03-Jul-2024
Updated on 03-Jul-2024
Home / DeveloperSection / Interviews / What are SQL Views?
Ravi Vishwakarma
03-Jul-2024SQL Server View is a virtual table derived from one or more tables or other views. It does not store data itself but rather represents a stored SQL query that dynamically retrieves data from its underlying tables whenever the view is queried.
Example
Employees Table:
Departments Table:
Now, let's create a view that shows the employees along with their department names:
In this example:
EmployeeDetails
.EmployeeID
,FirstName
,LastName
,DepartmentName
, andSalary
from theEmployees
table (e
) and theDepartments
table (d
).Employees
table with theDepartments
table based on theDepartmentID
column to retrieve the department name for each employee.EmployeeDetails
view now provides a consolidated view of employee details along with their department names.After creating the view, you can query it just like a regular table:
Read more
Why do you use SQL Command and Queries in SQL Server?
What is SQL Database and why is it so popular?
Write a query to retrieve the total number of employees in each department.